package cn.heyige.backend.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "占卜结果响应V2")
public class DivinationResultV2 {
    
    @Schema(description = "占卜ID", example = "div_1704096600123")
    private String divinationId;
    
    @Schema(description = "占卜问题", example = "今日运势如何？")
    private String question;
    
    @Schema(description = "占卜类型", allowableValues = {"TIME", "NUMBER", "IMAGE", "TEXT"})
    private String divinationType;
    
    @Schema(description = "占卜时间")
    private LocalDateTime divinationTime;
    
    @Schema(description = "算法类型")
    private String algorithm;
    
    @Schema(description = "卦象信息")
    private HexagramInfo hexagram;
    
    @Schema(description = "计算过程")
    private CalculationInfo calculation;
    
    @Schema(description = "图片分析（仅图片起卦）")
    private ImageAnalysis imageAnalysis;
    
    @Schema(description = "文本分析（仅文本起卦）")
    private TextAnalysis textAnalysis;
    
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "卦象信息")
    public static class HexagramInfo {
        @Schema(description = "卦象ID")
        private Long id;
        
        @Schema(description = "卦象名称", example = "地天泰")
        private String name;
        
        @Schema(description = "卦象编码", example = "DI_TIAN_TAI")
        private String code;
        
        @Schema(description = "上卦")
        private TrigramInfo upperTrigram;
        
        @Schema(description = "下卦")
        private TrigramInfo lowerTrigram;
        
        @Schema(description = "卦辞")
        private String hexagramText;
        
        @Schema(description = "五行关系")
        private String elementRelation;
    }
    
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "三元组信息")
    public static class TrigramInfo {
        @Schema(description = "名称", example = "坤")
        private String name;
        
        @Schema(description = "符号", example = "☷")
        private String symbol;
        
        @Schema(description = "五行", example = "土")
        private String element;
    }
    
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "计算信息")
    public static class CalculationInfo {
        @Schema(description = "年份")
        private Integer year;
        
        @Schema(description = "月份")
        private Integer month;
        
        @Schema(description = "日期")
        private Integer day;
        
        @Schema(description = "小时")
        private Integer hour;
        
        @Schema(description = "分钟")
        private Integer minute;
        
        @Schema(description = "上卦数字")
        private Integer upperNumber;
        
        @Schema(description = "下卦数字")
        private Integer lowerNumber;
        
        @Schema(description = "变爻")
        private List<Integer> changeLines;
        
        @Schema(description = "计算公式")
        private String formula;
        
        @Schema(description = "输入数字")
        private List<Integer> inputNumbers;
        
        @Schema(description = "关键词权重")
        private Map<String, Double> keywordWeights;
        
        @Schema(description = "文本哈希值")
        private String textHash;
    }
    
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "图片分析")
    public static class ImageAnalysis {
        @Schema(description = "图片URL")
        private String imageUrl;
        
        @Schema(description = "文件大小")
        private Long fileSize;
        
        @Schema(description = "图片尺寸")
        private Dimensions dimensions;
        
        @Schema(description = "哈希值")
        private String hash;
        
        @Schema(description = "主要颜色")
        private List<String> dominantColors;
        
        @Schema(description = "图片特征")
        private ImageFeatures features;
        
        @Data
        @Builder
        @AllArgsConstructor
        @NoArgsConstructor
        @Schema(description = "图片尺寸")
        public static class Dimensions {
            @Schema(description = "宽度")
            private Integer width;
            
            @Schema(description = "高度")
            private Integer height;
        }
        
        @Data
        @Builder
        @AllArgsConstructor
        @NoArgsConstructor
        @Schema(description = "图片特征")
        public static class ImageFeatures {
            @Schema(description = "亮度")
            private Double brightness;
            
            @Schema(description = "对比度")
            private Double contrast;
            
            @Schema(description = "饱和度")
            private Double saturation;
        }
    }
    
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "文本分析")
    public static class TextAnalysis {
        @Schema(description = "输入文本")
        private String inputText;
        
        @Schema(description = "关键词")
        private List<String> keywords;
        
        @Schema(description = "情感倾向")
        private String sentiment;
        
        @Schema(description = "实体识别")
        private List<Entity> entities;
        
        @Schema(description = "文本哈希值")
        private String textHash;
        
        @Data
        @Builder
        @AllArgsConstructor
        @NoArgsConstructor
        @Schema(description = "实体")
        public static class Entity {
            @Schema(description = "文本")
            private String text;
            
            @Schema(description = "类型")
            private String type;
            
            @Schema(description = "置信度")
            private Double confidence;
        }
    }
}